package com.ymatou.auth.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.auth.parameter.UserBillsPasRequestDtoBean;
import com.ymatou.auth.service.UserBillsPasRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.utils.TestDataManager;
/**
*根据用户ID查询最后更新交易密码的时间
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserBillsPasRequestDto{
	private static UserBillsPasRequestDtoBean userbillspasrequestdtoBean;
	private static UserBillsPasRequestDtoCall userbillspasrequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据用户ID查询最后更新交易密码的时间");
	}

	@Before
	public void caseUp() {
		userbillspasrequestdtoBean=new UserBillsPasRequestDtoBean();
		userbillspasrequestdtoCall=new UserBillsPasRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(userbillspasrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UserBillsPasRequestDto_001() {
		Logger.start(true,"根据用户ID查询最后更新登入密码的时间,成功");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			
			UserCallService.resetLoginPassword(userId, "654321");
			Thread.sleep(3000);
			userbillspasrequestdtoBean.setUserId(userId);
			userbillspasrequestdtoBean.setPType(1);
			userbillspasrequestdtoCall.setData(userbillspasrequestdtoBean);
			userbillspasrequestdtoCall.callService();			
			Logger.verifyEquals("true", userbillspasrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyNotNull(userbillspasrequestdtoCall.getString("Result"), "验证Result非空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserBillsPasRequestDto_002() {
		Logger.start(true,"根据用户ID查询最后更新支付密码的时间,成功");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			
			AuthCallService.updatePayPassWord(String.valueOf(userId), "a1b2c3");
			
			userbillspasrequestdtoBean.setUserId(userId);
			userbillspasrequestdtoBean.setPType(2);
			userbillspasrequestdtoCall.setData(userbillspasrequestdtoBean);
			userbillspasrequestdtoCall.callService();			
			Logger.verifyEquals("true", userbillspasrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyNotNull(userbillspasrequestdtoCall.getString("Result"), "验证Result非空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UserBillsPasRequestDto_003() {
		Logger.start(false,"输入userid错误,失败");
		try {
			userbillspasrequestdtoBean.setUserId(-1000);
			userbillspasrequestdtoBean.setPType(2);
			userbillspasrequestdtoCall.setData(userbillspasrequestdtoBean);
			userbillspasrequestdtoCall.callService();			
			Logger.verifyEquals("false", userbillspasrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyIsContains("用户ID错误",  userbillspasrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_UserBillsPasRequestDto_004() {
		Logger.start(false,"不输入ptype,失败");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			
			
			userbillspasrequestdtoBean.setUserId(userId);
//			userbillspasrequestdtoBean.setPType(2);
			userbillspasrequestdtoCall.setData(userbillspasrequestdtoBean);
			userbillspasrequestdtoCall.callService();			
			Logger.verifyEquals("false", userbillspasrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyIsContains("用户密码类型错误", userbillspasrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserBillsPasRequestDto_005() {
		Logger.start(false,"未设置过交易密码根据用户ID查询最后更新支付密码的时间");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			
			
			userbillspasrequestdtoBean.setUserId(userId);
			userbillspasrequestdtoBean.setPType(2);
			userbillspasrequestdtoCall.setData(userbillspasrequestdtoBean);
			userbillspasrequestdtoCall.callService();			
			Logger.verifyIsContains("未找到密码更新记录", userbillspasrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyEquals("false", userbillspasrequestdtoCall.getString("Success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UserBillsPasRequestDto_006() {
		Logger.start(true,"重置过交易密码根据用户ID查询最后更新支付密码的时间");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			
			AuthCallService.updatePayPassWord(String.valueOf(userId), "a1b2c3");
			
			userbillspasrequestdtoBean.setUserId(userId);
			userbillspasrequestdtoBean.setPType(2);
			userbillspasrequestdtoCall.setData(userbillspasrequestdtoBean);
			userbillspasrequestdtoCall.callService();			
			Logger.verifyEquals("true", userbillspasrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyNotNull(userbillspasrequestdtoCall.getString("Result"), "验证Result非空");
			String result1=userbillspasrequestdtoCall.getString("Result");
			Thread.sleep(1000);
			AuthCallService.updatePayPassWord(String.valueOf(userId), "a1b2c3");
			userbillspasrequestdtoCall=new UserBillsPasRequestDtoCall();
			userbillspasrequestdtoCall.setData(userbillspasrequestdtoBean);
			userbillspasrequestdtoCall.callService();
			Logger.verifyEquals("true", userbillspasrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyNotNull(userbillspasrequestdtoCall.getString("Result"), "验证Result非空");
			String result2=userbillspasrequestdtoCall.getString("Result");
			Logger.verifyNotEquals(result1, result2,"验证Result变化");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UserBillsPasRequestDto_007() {
		Logger.start(false,"未设置过登入密码根据用户ID查询最后更新支付密码的时间");
		try {
			String ip=TestDataManager.getRandomIp();
			String email=TestDataManager.getEmail();
			String phone=TestDataManager.getPhoneNum();
			Map UserMap =UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			Integer userId = Integer.valueOf(UserMap.get("userId").toString());
			String UserName = (String) UserMap.get("loginId");
			
			
			userbillspasrequestdtoBean.setUserId(userId);
			userbillspasrequestdtoBean.setPType(1);
			userbillspasrequestdtoCall.setData(userbillspasrequestdtoBean);
			userbillspasrequestdtoCall.callService();			
			Logger.verifyIsContains("未找到密码更新记录", userbillspasrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyEquals("false", userbillspasrequestdtoCall.getString("Success"), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}